package com.example.a1.myapplication.activity;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.example.a1.myapplication.R;
import com.example.a1.myapplication.constants.PushConstant;
import com.example.a1.myapplication.utils.PushUtils;

public class PushActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_push);
        PushUtils.getInstance(this).registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                Toast.makeText(getApplicationContext(), intent.getStringExtra(PushConstant.PUSH_MESSAGE), Toast.LENGTH_LONG).show();
            }
        });
        findViewById(R.id.bPush).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PushUtils.getInstance(getApplicationContext()).push(PushConstant.PUSH_TYPE_SYSTEM_NOTICES, "智能", "456");
            }
        });
    }

    @Override
    protected void onDestroy() {
        PushUtils.getInstance(this).unregisterReceiver();
        super.onDestroy();
    }
}
